package process_demo.review.other_locks.read_write_lock;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
 * 读写锁
 * 读 + 读 可以共享
 * 读 + 写 互斥
 * 写 + 写 互斥
 * @author haomin
 * @date 2022/09/20 17:31
 **/
public class Main {
    public static void main(String[] args) {
        ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
        Lock readLock = readWriteLock.readLock();
        Lock writeLock = readWriteLock.writeLock();

        readLock.lock();
        Thread t = new Thread(){
            @Override
            public void run() {
                readLock.lock();
                System.out.println("读+读 可以访问到");
            }
        };

        t.start();
    }
}